/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package fr.ove.openmath.jome.ctrl.amto;

/**
 *
 * @author Mr.Sam
 */
import fr.ove.openmath.jome.ctrl.linear.events.LinearParserEvent;
import fr.ove.openmath.jome.ctrl.amto.MapsToUnary;

/**
* The abstract math tree object of a postfixed unary operator.
*
* @author © 1999 DIRAT Laurent
* @version 1.0  18/11/1999
*/
public abstract class MapsToPostfixedUnary extends MapsToUnary {
    /**
    * The constructor.
    * @param identifier the identifier of the instance.
    * @param token the identifier of the instance by the mean of the event sent.
    */
    public MapsToPostfixedUnary(String identifier, int token) {
        super(identifier, token);
    }
    
    /**
    * "Flushes" the object as a sequence of events for the building of the model
    */
    public void flush() {
        AbstractMathTreeObject child = getChild(0);
        if (!(child instanceof MapsToTerminal)) {
            LinearParserEvent linearParserEvent = new LinearParserEvent(getEventSource());
            // The opening
            linearParserEvent.setToken(LinearParserEvent.OPEN_PAREN, "(");
            fireLinearParserEvent(linearParserEvent);
            
            super.flush();
            
            // The closing
            linearParserEvent.setToken(LinearParserEvent.CLOSE_PAREN, ")");
            fireLinearParserEvent(linearParserEvent);
            
        }
        else
            super.flush();
        
        LinearParserEvent linearParserEvent = new LinearParserEvent(getEventSource());
        linearParserEvent.setToken(token, param);
        fireLinearParserEvent(linearParserEvent);
    }
}